/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-18 11:18:29
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-18 15:37:44
 */
import 'package:flutter_data_center/model/broadcast/broadcast_model.dart';
import 'package:flutter_data_center/model/common/menu_model.dart';
import 'package:flutter_data_center/net/dio_utils.dart';
import 'package:get/get.dart';

class BroadcaseController extends GetxController {
  // 正在播放的广播信息
  BroadcasePlayingModel _playing;
  BroadcasePlayingModel get playing => _playing;

  void getPlaying() async {
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.broadcastPlaying,
    );
    if (responseInfo.success) {
      var data = responseInfo.data;
      _playing = BroadcasePlayingModel.fromJson(data);
      update();
    }
  }

  // 任务清单列表
  List<BroadcaseTaskModel> _taskList = [];
  List get taskList => _taskList;
  void getTaskList() async {
    _taskList = [];
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.broadcastTasks,
    );
    if (responseInfo.success) {
      var data = responseInfo.data;
      for (var item in data) {
        _taskList.add(BroadcaseTaskModel.fromJson((item)));
      }
      update();
    }
  }

  // 文件列表
  List<BroadcaseFileModel> _fileList = [];
  List get fileList => _fileList;
  void getFileList() async {
    _fileList = [];
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.broadcastFiles,
    );
    if (responseInfo.success) {
      var data = responseInfo.data;
      for (var item in data) {
        _fileList.add(BroadcaseFileModel.fromJson((item)));
      }
      update();
    }
  }

  // 菜单
  List<MenuModel> _menus = [
    MenuModel("任务单", "task"),
    MenuModel("临时", "current"),
  ];
  List<MenuModel> get menus => _menus;
}
